﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dawn_of_Man
{
    [Serializable()]
    public class StorageHut : Building
    {
        //public String name = "Storage Hut";
        //public int size { get; set; }
        public int storage = 50;
        public int clay = 0;
        public int hide = 0;
        public int stone = 0;
        public int water = 0;
        public int wheat = 0;
        public int meat = 0;
        public int wood = 0;
        public int tool = 0;
        public int weapon = 0;
        public int block = 0;

        [field: NonSerialized]
        public event EventHandler Changed;

        // Invoke the Changed event; called whenever list changes:
        [field: NonSerialized]
        protected virtual void OnChanged(EventArgs e)
        {
            if (Changed != null)
                Changed(this, e);
        }

        public override string ToString()
        {
            return name;
        }

        public int getStorageCapacity()
        {
            return storage * size;
        }

        public bool addRessource(Ressource res)
        {
                switch (res.name)
                {
                    case "Clay":
                        if (clay < storage)
                        {
                            clay++;
                            break;
                        }
                        else
                            return false;
                    case "Hide":
                        if (hide < storage)
                        {
                            hide++;
                            break;
                        }
                        else
                            return false;
                    case "Stone":
                        if (stone < storage)
                        {
                            stone++;
                            break;
                        }
                        else
                            return false;
                    case "Water":
                        if (water < storage)
                        {
                            water++;
                            break;
                        }
                        else
                            return false;;
                    case "Wheat":
                        if (wheat < storage)
                        {
                            wheat++;
                            break;
                        }
                        else
                            return false;
                    case "Meat":
                        if (meat < storage)
                        {
                            meat++;
                            break;
                        }
                        else
                            return false;
                    case "Wood":
                        if (wood < storage)
                        {
                            wood++;
                            break;
                        }
                        else
                            return false;
                    case "Tool":
                        if (tool < storage)
                        {
                            tool++;
                            break;
                        }
                        else
                            return false;
                    case "Weapon":
                        if (weapon < storage)
                        {
                            weapon++;
                            break;
                        }
                        else
                            return false;
                    case "Block":
                        if (block < storage)
                        {
                            block++;
                            break;
                        }
                        else
                            return false;
                    default:
                        return false;
                }
                OnChanged(EventArgs.Empty);
                return true;
        }




        public bool removeRessource(Ressource res)
        {
            if (res.name == "Clay")
                if (clay - 1 >= 0)
                {
                    clay--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Hide")
                if (hide - 1 >= 0)
                {
                    hide--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Stone")
                if (stone - 1 >= 0)
                {
                    stone--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Water")
                if (water - 1 >= 0)
                {
                    water--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Wheat")
                if (wheat - 1 >= 0)
                {
                    wheat--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Meat")
                if (meat - 1 >= 0)
                {
                    meat--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Wood")
                if (wood - 1 >= 0)
                {
                    wood--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Tool")
                if (tool - 1 >= 0)
                {
                    tool--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Weapon")
                if (weapon - 1 >= 0)
                {
                    weapon--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else if (res.name == "Block")
                if (block - 1 >= 0)
                {
                    block--;
                    OnChanged(EventArgs.Empty);
                    return true;
                }
                else
                    return false;
            else
                return false;
        }

        private int countStorage()
        {
            return clay + stone + meat + hide + wheat + wood + water;
        }

        public Ressource GetRessourceType(String name)
        {
            Ressource res = new Ressource();
            switch (name)
            {
                case "Clay":
                    res.name = "Clay";
                    break;
                case "Stone":
                    res.name = "Stone";
                    break;
                case "Wood":
                    res.name = "Wood";
                    break;
                case "Wheat":
                    res.name = "Wheat";
                    break;
                case "Meat":
                    res.name = "Meat";
                    break;
                case "Water":
                    res.name = "Water";
                    break;
                case "Hide":
                    res.name = "Hide";
                    break;
                case "Tool":
                    res.name = "Tool";
                    break;
                case "Weapon":
                    res.name = "Weapon";
                    break;
                case "Block":
                    res.name = "Block";
                    break;
            }
            return res;
        }
    }
}
